<html>
<head><meta charset="utf-8"><title>Put macros inside appropriate modules · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html">Put macros inside appropriate modules</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239857772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239857772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239857772">(May 22 2021 at 08:52)</a>:</h4>
<p>Since now we can have macros living inside modules instead of the root of std/core, example being <code>ptr::addr_of</code>, I propose moving other macros.</p>
<p>This shouldn't be a breaking change, because they still can be exposed via prelude.</p>
<ul>
<li><code>asm!</code>/<code>llvm_asm!</code>/<code>global_asm!</code> - someone proposed to put them inside <code>core::arch::$ARCH</code></li>
<li><code>is_$ARCH_feature_detected!</code> -&gt; <code>std::arch::$ARCH::is_feature_detected</code></li>
<li><code>env!</code>/<code>option_env!</code> -&gt; <code>std::env</code></li>
<li><code>print!</code> family -&gt; <code>std::io</code></li>
<li><code>write!</code> family -&gt; <code>core::fmt</code> or <code>core::io</code></li>
<li><code>format!</code> -&gt; <code>std::fmt</code> (it kinda conflicts with current <code>std::fmt::format</code> function)</li>
<li><code>format_args!</code> -&gt; <code>core::fmt</code></li>
<li><code>panic!</code> -&gt; <code>core::panic</code></li>
<li><code>thread_local!</code> -&gt; <code>std::thread::thread_local</code></li>
<li><code>todo!</code>/<code>unimplemented!</code>/<code>unreachable!</code> -&gt; <code>core::hint</code></li>
<li><code>vec!</code> -&gt; <code>std::vec</code></li>
</ul>



<a name="239874550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239874550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239874550">(May 22 2021 at 13:58)</a>:</h4>
<p>you can currently call them like <code>std::env!("...")</code>, which would break if they were moved</p>



<a name="239888513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239888513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239888513">(May 22 2021 at 17:43)</a>:</h4>
<p>We could absolutely move them, as long as we keep them callable at the top level and in the prelude. That may or may not have value.</p>



<a name="239889011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239889011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239889011">(May 22 2021 at 17:52)</a>:</h4>
<p>Yes, you could move them in the same way that any other item gets "moved", by leaving a shim in the old location that passes through to the new location.</p>



<a name="239889087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239889087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239889087">(May 22 2021 at 17:54)</a>:</h4>
<p>An argument that I like for moving them is that it makes the docs more intuitive; I would expect the <code>println!</code> docs to live in <code>std::io</code>, not in the crate root. The converse is also true: if I'm looking at the API index as represented by the crate root, I likely don't want to be shown this great big grab bag of random macros.</p>



<a name="239890998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239890998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BurntSushi <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239890998">(May 22 2021 at 18:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="256342">bstrie</span> <a href="#narrow/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules/near/239889087">said</a>:</p>
<blockquote>
<p>I likely don't want to be shown this great big grab bag of random macros.</p>
</blockquote>
<p>yeah this is one of the benefits i look forward to the most.</p>
<p>otherwise, having macros in their corresponding modules sounds like a good idea to me. i think we should be careful with churn (as always), but otherwise think it's the right direction to move in.</p>



<a name="239892421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239892421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239892421">(May 22 2021 at 18:51)</a>:</h4>
<p>heck, I might just submit a PR for that this weekend. not all the prelude macros necessarily <em>have</em> good modules to live in, so I'll ignore those for now to avoid bikeshedding, but it seems reasonable to start with the macros with "obvious" places to live and leave the rest to an RFC</p>



<a name="239939653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239939653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239939653">(May 23 2021 at 10:04)</a>:</h4>
<p>Please skip <code>asm!</code>. The placement of that one has been through a lot of bikeshed already.</p>



<a name="239945850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239945850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239945850">(May 23 2021 at 11:58)</a>:</h4>
<p><code>env!</code> should be renamed <code>var!</code> if it’s exported under <code>std::env</code> to reduce the repetitiveness IMO. <code>env!</code> made sense when called with no prefix.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">std</span>::<span class="n">env</span>::<span class="fm">env!</span><span class="p">(</span><span class="s">"foo"</span><span class="p">);</span><span class="w"></span>
<span class="n">std</span>::<span class="n">env</span>::<span class="n">var</span><span class="o">!</span><span class="p">(</span><span class="s">"foo"</span><span class="p">);</span><span class="w"></span>

<span class="n">std</span>::<span class="n">env</span>::<span class="fm">option_env!</span><span class="p">(</span><span class="s">"foo"</span><span class="p">);</span><span class="w"></span>
<span class="n">std</span>::<span class="n">env</span>::<span class="n">option_var</span><span class="o">!</span><span class="p">(</span><span class="s">"foo"</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="239946246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239946246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239946246">(May 23 2021 at 12:04)</a>:</h4>
<p><code>std::env::var!</code> is potentially confusing with <code>std::env::var</code>. At least, imo, it might cause some confusion.</p>



<a name="239954710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239954710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239954710">(May 23 2021 at 14:23)</a>:</h4>
<p>yes, I won't be touching asm!. The goal is to make this PR as non-contentious as possible.</p>



<a name="239954788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239954788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239954788">(May 23 2021 at 14:24)</a>:</h4>
<p>Note that all of these macros will still be exported from the prelude, as required by backwards-compatibility, so I'm not too worried about <code>std::env::env!</code>, since people will still be using it as <code>env!</code></p>



<a name="239954939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239954939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239954939">(May 23 2021 at 14:27)</a>:</h4>
<p>I’m mildly opposed to having <code>env!</code> and <code>option_env!</code> in <code>std::env</code>. The module is documented as "Inspection and manipulation of the process’s environment." <strong>The</strong> process is implicitly the run-time process executing the code being compiled, whereas <code>env!</code> and <code>option_env!</code> access variables of the environment the compiler is running in.</p>



<a name="239955043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239955043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239955043">(May 23 2021 at 14:29)</a>:</h4>
<p>that sounds like contention, so I won't move them :P</p>



<a name="239955196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239955196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239955196">(May 23 2021 at 14:31)</a>:</h4>
<p>if nothing else this will reveal how many macros have corresponding, non-contentious modules :)</p>



<a name="239955255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239955255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239955255">(May 23 2021 at 14:32)</a>:</h4>
<p>of course, one could argue that if macro namespacing had been in the language since 1.0 then people would have put <code>env!</code> in <code>std::env</code> anyway, but I'll leave that to a future RFC</p>



<a name="239981792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239981792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239981792">(May 23 2021 at 22:13)</a>:</h4>
<p>even if we'd had macro namespacing from the start, it would still be something like <code>core::compile_time::env!</code>, since that's what the macro is actually about.</p>



<a name="239984924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239984924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239984924">(May 23 2021 at 23:11)</a>:</h4>
<p>and maybe <code>core::compile_time::concat!</code> and <code>core::compile_time::include_bytes!</code> and friends?</p>



<a name="239987234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/239987234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#239987234">(May 23 2021 at 23:55)</a>:</h4>
<p>a lot of the macros really want to live in a hypothetical <code>compile_time</code> (or maybe <code>meta</code>?) module, purely due to the nature of what macros get used for due to when they run compared to regular functions. that said, <code>concat</code> and <code>include_bytes</code> could live in <code>std::str</code> and <code>std::array</code>. I don't intend to touch those for now, my first PR is just going to be for the <code>std::io</code> macros.</p>



<a name="240001550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240001550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240001550">(May 24 2021 at 04:04)</a>:</h4>
<p><span class="user-mention" data-user-id="256342">@bstrie</span> <code>std::str::concat!</code> seems sensible to me.</p>



<a name="240001556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240001556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240001556">(May 24 2021 at 04:04)</a>:</h4>
<p>And then <code>concat_bytes</code> and <code>include_bytes</code> can live somewhere appropriate for slice-y things.</p>



<a name="240004521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240004521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240004521">(May 24 2021 at 04:43)</a>:</h4>
<p>I mean would think the fact that it’s a macro would intuit that something is happening at compile-time, as these macros are no different from proc macros in third party crates these days.</p>



<a name="240027925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240027925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240027925">(May 24 2021 at 09:39)</a>:</h4>
<p>Maybe. A proc-macro can expand to code that does something at runtime, in the same way that <code>println!</code> does not make the compiler print something</p>



<a name="240036372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240036372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240036372">(May 24 2021 at 11:08)</a>:</h4>
<blockquote>
<p>I might just submit a PR for that this weekend</p>
</blockquote>
<p>i'd really prefer to see a RFC first before starting to move all these things around. we should first make sure the eventual goal is clear and agreeable</p>



<a name="240092279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240092279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240092279">(May 24 2021 at 18:34)</a>:</h4>
<p>I'm happy to author an RFC, but IMO the parts that need discussion are the means, not the goals. It goes without saying that items in the stdlib ought to be defined in submodules (even items that have always been exported from the prelude, like <code>Option</code>), and that the current un-namespaced state of macros in std is an artifact of technical limitations as of Rust 1.0 (similar to how <code>std::i32::MAX</code> was a merely an artifact of the lack of associated consts until Rust 1.1). Furthermore, past discussions have indicated that future macro additions should be namespaced (<code>std::task::ready</code>, <code>std::ptr::addr_of</code>), so the use of namespacing on macros is not contentious. The goals are given above: in a concrete sense to improve the documentation, in an abstract sense to make the stdlib more intuitive. What needs to be discussed is where things ought to live, but not all macros need that discussion; I find it safe to presume that people will concur that <code>println!</code> should go in <code>std::io</code>.</p>



<a name="240092435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240092435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240092435">(May 24 2021 at 18:35)</a>:</h4>
<p>It still seems like a large enough change to warrant an RFC</p>



<a name="240092558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240092558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240092558">(May 24 2021 at 18:36)</a>:</h4>
<p>In any case I'm putting aside that PR for now, because there's a more fundamental prerequisite: macro definitions need to be migrated from macros 1.0 to macros 2.0 if they ever want to be namespaced. I'll start there, since I'm not even sure how mature the macros 2.0 implementation is right now (it gets used a lot, but largely for builtins).</p>



<a name="240093124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240093124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240093124">(May 24 2021 at 18:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules/near/240092435">said</a>:</p>
<blockquote>
<p>It still seems like a large enough change to warrant an RFC</p>
</blockquote>
<p>For the large majority of the macros, I agree. For the specific case of <code>std::io::println!</code> I would suggest otherwise, and that if people can't even agree on such a small change as that then I would be rather dim on the prospects of the broader RFC. Or to put it another way, if people aren't keen on <code>std::io::println!</code>, then I don't see how I'd possibly persuade them by offering to move even <em>more</em> macros. :P</p>



<a name="240094782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240094782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240094782">(May 24 2021 at 18:53)</a>:</h4>
<p>(and before I go trying to move the stdlib to macros 2.0 I'll start by moving the compiler to macros 2.0; dogfooding and all that :P )</p>



<a name="240100735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240100735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mara <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240100735">(May 24 2021 at 19:35)</a>:</h4>
<blockquote>
<p>It goes without saying [..]</p>
</blockquote>
<p>that's a big assumption. regardless, we should discuss changes like that on an rfc, even if they are uncontroversial. we should have an overview of such changes together with all the relevant context and pros and cons</p>
<blockquote>
<p>if people can't even agree on such a small change as that then</p>
</blockquote>
<p>this confuses me. asking for an RFC isn't disagreeing. it means "yes, sounds good. let's discuss this."</p>



<a name="240201475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240201475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240201475">(May 25 2021 at 15:05)</a>:</h4>
<p>A large value of the RFC, even if we all immediately agree on all points, is that RFCs get much more publicity within the wider rust world than any PR.</p>



<a name="240210998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240210998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240210998">(May 25 2021 at 16:04)</a>:</h4>
<p>I wonder if it would be in-scope for the RFC to discuss namespacing <em>attributes</em> as well, since 1) they're already defined as proc macros in the stdlib (although often just as builtins) and 2) I'm always annoyed that I have to look in the reference for their documentation rather than the API docs. There could be <code>std::hint::inline</code>, <code>std::mem::repr</code>, <code>std::panic::panic_handler</code>, etc. But maybe other people think of these as language features rather than library features.</p>



<a name="240214106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240214106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240214106">(May 25 2021 at 16:27)</a>:</h4>
<p><span class="user-mention" data-user-id="256342">@bstrie</span> FWIW I think they should, all macros or macro-like builtin should be at least considered.</p>



<a name="240217267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240217267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240217267">(May 25 2021 at 16:50)</a>:</h4>
<p>I do think of most attributes as being language features rather than proc-macros, particularly the ones you couldn't implement yourself within a crate not part of the standard library.</p>



<a name="240219510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240219510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240219510">(May 25 2021 at 17:07)</a>:</h4>
<p>That's a good point, although there are also non-macros that couldn't be defined apart from the stdlib; consider the <code>Copy</code> trait. And interestingly the <code>Copy</code> derive macro is already namespaced in <code>std::marker</code>. The nature of the stdlib kind of makes the line between language and library fuzzy.</p>



<a name="240220013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240220013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240220013">(May 25 2021 at 17:11)</a>:</h4>
<p>Copy is marked as <code>lang</code> in the source ;3</p>



<a name="240220402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240220402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240220402">(May 25 2021 at 17:14)</a>:</h4>
<p>indeed, but I find the distinction between lang items, builtins, and intrinsics to be semi-arbitrary :)</p>



<a name="240220457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240220457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240220457">(May 25 2021 at 17:14)</a>:</h4>
<p>I think, if we could organize it from scratch, then <code>core::lang</code> would just be the home of all the lang item things all at once. Also <code>alloc::lang</code> for Box, and maybe <code>std::lang</code> if necessary (I dunno if there's std-only lang items)</p>
<p>But that's not the world we live in, so whatever. Getting macros out of the crate root is of some mild value, but we don't need to worry about absolutely perfect, just avoid deceptive paths</p>



<a name="240220587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240220587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240220587">(May 25 2021 at 17:16)</a>:</h4>
<p>to be clear, while I do like the "niceness" of having things live in their proper place, I think most of the concrete benefit here would be in putting docs in places where users are likely to look for them</p>



<a name="240221222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240221222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240221222">(May 25 2021 at 17:20)</a>:</h4>
<p>oh i essentially never look for items in modules. Search is too good for that</p>



<a name="240221613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240221613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240221613">(May 25 2021 at 17:23)</a>:</h4>
<p>search works when you know what you're looking for, but it's not useful for organic discovery. For example I would like people to organically learn about the existence <code>writeln!</code> merely by scanning the <code>std::io</code> docs.</p>



<a name="240222871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240222871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240222871">(May 25 2021 at 17:32)</a>:</h4>
<p><span class="user-mention" data-user-id="256342">@bstrie</span> I do think that's a good argument.</p>



<a name="240222942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240222942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240222942">(May 25 2021 at 17:33)</a>:</h4>
<p>In particular, if there's somewhere that module docs already say "also see this macro", that's a good hint for where the macro belongs.</p>



<a name="240223365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240223365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240223365">(May 25 2021 at 17:36)</a>:</h4>
<p><code>format!</code> and <code>format_args!</code> and similar probably belong in <code>std::fmt</code> for instance.</p>



<a name="240261920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240261920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240261920">(May 25 2021 at 23:13)</a>:</h4>
<p>format_args maybe, but format is defined in alloc and used to make String values, so it feels like it should live wherever you find the String type (in alloc, or re-exported in std)</p>



<a name="240287962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240287962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240287962">(May 26 2021 at 07:30)</a>:</h4>
<p>This is why we have an <code>alloc::fmt</code> module which reexports the contents of <code>core::fmt</code>, instead of itself being a reexport</p>



<a name="240379697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Put%20macros%20inside%20appropriate%20modules/near/240379697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kestrer <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Put.20macros.20inside.20appropriate.20modules.html#240379697">(May 26 2021 at 19:41)</a>:</h4>
<p>We already have <code>std::fmt::format</code> for converting <code>Arguments</code> to a <code>String</code> so it makes sense for <code>std::fmt::format!</code> to be there too.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>